package com.example.demo.convert;


import com.alibaba.fastjson.serializer.ValueFilter;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/***
 * 统一时间格式转换
 */
public class DateTimeFormatConvert implements ValueFilter {

    public static final String FORMAT = "yyyy年MM月dd日 HH:mm:ss";


    @Override
    public Object process(Object instance, String name, Object value) {
        if (instance == null || name == null || value == null) {
            return value;
        }

        if (!(value instanceof LocalDateTime)  ) {
            return value;
        }
        return ((LocalDateTime) value).format(DateTimeFormatter.ofPattern(FORMAT));
    }
}
